package com.ruoyi.web.controller.video;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.service.ISysDictTypeService;
import com.ruoyi.video.domain.BusMemberStore;
import com.ruoyi.video.domain.BusVideoInfo;
import com.ruoyi.video.service.IMemberStoreService;
import com.ruoyi.video.service.IVideoInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 轮播图 信息操作处理
 * 
 * @author ruoyi
 */
@Api("会员收藏信息管理")
@RestController
@RequestMapping("/bus/store")
public class BusMemberStoreController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(BusCarouselController.class);

    @Autowired
    private IVideoInfoService videoInfoService;

    @Autowired
    private ISysDictTypeService dictTypeService;

    @Autowired
    private IMemberStoreService memberStoreService;

    /**
     * 获取用户收藏列表
     */
    @ApiOperation("获取用户收藏列表")
    @PreAuthorize("@ss.hasPermi('bus:store:list')")
    @GetMapping("/list/{memberId}")
    public TableDataInfo list(@PathVariable("memberId")String memberId) {
        List<BusMemberStore> storeList = memberStoreService.selectMemberStoreList(memberId);
        List<BusVideoInfo> videoInfoList = new ArrayList<>();
        List<Long> videoIdList = new ArrayList<>();
        for (BusMemberStore store : storeList) {
            videoIdList.add(store.getVideoId());
        }
        if (videoIdList == null || videoIdList.size() == 0) {
            return getDataTable(videoInfoList);
        }
        startPage();
        List<SysDictData> videoTagDictList = dictTypeService.selectDictDataByType("video_tag");
        List<SysDictData> videoTypeDictList = dictTypeService.selectDictDataByType("video_type");
        videoInfoList = videoInfoService.selectVideoByIdList(videoIdList);
        videoInfoService.formatVideoList(videoInfoList, videoTagDictList, videoTypeDictList);
        return getDataTable(videoInfoList);
    }


}
